package org.lex.game.sudoku.model.builder;

import org.lex.game.sudoku.model.DefaultSudokuModel;
import org.lex.game.sudoku.model.SudokuModel;
import org.lex.game.sudoku.model.SudokuModelListener.Cause;

import cn.mjc.game.sudoku.ExhaustiveNResolver;
import cn.mjc.game.sudoku.NPalace;

public class NPalaceSudokuBuilder implements SudokuBuilder {

	public static void main(String[] args) {
		NPalaceSudokuBuilder builder = new NPalaceSudokuBuilder();
		SudokuModel model = new DefaultSudokuModel();
		model.newGame(builder);

		System.out.print(model);
	}

	@Override
	public void build(SudokuModel model) {
		// 创建一个默认的9宫格，nsize=3
		NPalace palace = NPalace.newInstance();

		// 对该数独使用递归穷举解析类进行解析获得答案
		palace.fill(new ExhaustiveNResolver(palace));

		// 在每一行上遮蔽掉3-7个数字供用户进行求解
		palace.shield(3, 7);

		int[][] data = palace.getUserValues();
		for (int row = 0, gridSize = model.getGridSize(); row < gridSize; row++) {
			for (int col = 0; col < gridSize; col++) {
				model.set(Cause.SYSTEM, row, col, data[row][col]);
			}
		}
	}

}
